#!usr/bin/env python
# -*- coding: utf-8 -*-
# author: kuangdd
# date: 2020/2/23
"""
"""

import frida  # 导入frida模块
import sys  # 导入sys模块

# 从此处开始定义用来Hook的javascript代码
jscode = """ 
    Java.perform(function(){  
        var MainActivity = Java.use('com.p993ss.android.ugc.aweme.main.MainActivity'); //获得MainActivity类
        MainActivity.getMainActivity.implementation = function(){ //Hook testFrida函数，用js自己实现
            send('Statr! Hook!'); //发送信息，用于回调python中的函数 
        }
    });
"""

#processes = frida.get_remote_device().enumerate_processes()
#for process in processes:
#    print(process)
#
#applications = frida.get_remote_device().enumerate_applications()
#for application in applications:
#	print(application)

front_app = frida.get_remote_device().get_frontmost_application()
print(front_app)



def on_message(message, data):  # js中执行send函数后要回调的函数
    print(message)
rdev = frida.get_remote_device()
#pid = frida.get_device('16463')
print(rdev)
process = frida.get_remote_device().attach('com.p993ss.android.ugc.aweme.main.MainActivity')
script = process.create_script(jscode)  # 创建js脚本
script.on('message', on_message)  # 加载回调函数，也就是js中执行send函数规定要执行的python函数
script.load()  # 加载脚本
sys.stdin.read()

#if __name__ == "__main__":
#    print(__file__)
    # test_sdk_api()
    # test_cli_api()
    # test_web_api()
   # test_http_server()
